package com.example.demo.huawei;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.PriorityQueue;
import java.util.Scanner;

// 执行任务赚取最多的积分
// 两个用例测不过
public class OD37 {


    public static class Job {
        // 任务最晚处理时间
        public int sla;
        // v表示任务对应的积分
        public int v;

        public Job(int sla, int v) {
            this.sla = sla;
            this.v = v;
        }

        public Job() {
        }

        @Override
        public String toString() {
            return "Job{" +
                    "sla=" + sla +
                    ", v=" + v +
                    '}';
        }
    }

    public static void main(String[] args) {

        Scanner sc = new Scanner(System.in);
        // 任务个数
        int n = sc.nextInt();
        // 可用于处理任务的时间
        int t = sc.nextInt();
        List<Job> jobs = new ArrayList<>();
        for (int i = 0; i < n; i++) {
            jobs.add(new Job(sc.nextInt(), sc.nextInt()));
        }
        System.out.println(getMaxScore(jobs, t));
    }


    public static int getMaxScore(List<Job> tasks, int T) {
        int maxScore = 0;
        List<PriorityQueue<Integer>> list = new ArrayList<>(T);

        for (int i = 0; i < T; ++i) {
            list.add(new PriorityQueue<>(Collections.reverseOrder()));
        }

        for (Job task : tasks) {
            if (task.sla - 1 < T) {
                list.get(task.sla - 1).add(task.v);
            }
        }

        PriorityQueue<Integer> availableTasks = new PriorityQueue<>(Collections.reverseOrder());
        for (int i = T - 1; i >= 0; --i) {
            availableTasks.addAll(list.get(i));
            if (!availableTasks.isEmpty()) {
                maxScore += availableTasks.poll();
            }
        }
        return maxScore;
    }

}
